﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;

using INSTA.StockApplication.BLL;

namespace INSTA.StockApplication.UI.Windows
{
    public partial class AddProduct : DevExpress.XtraEditors.XtraForm
    {
        public AddProduct()
        {
            InitializeComponent();
            comboBox1.DataSource = Brands.GetListMarqueFromDatabase();
            comboBox1.ValueMember = "ID_MARQUE";
            comboBox1.DisplayMember = "NOM_MARQUE";
            comboBox2.DataSource = Provider.GetListFournisseurFromDatabase();
            comboBox2.ValueMember = "ID_FOURNISSEUR";
            comboBox2.DisplayMember = "NOM_FOURNISSEUR";
            comboBox3.DataSource = Category.GetListCategorieFromDatabase();
            comboBox3.ValueMember = "ID_CATEGORIE";
            comboBox3.DisplayMember = "LIBELLE_CATEGORIE";
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            if(textEdit1.Text !="")
            {
                string nom = textEdit1.Text;
                int marque = Convert.ToInt32(comboBox1.SelectedValue);
                int four = Convert.ToInt32(comboBox2.SelectedValue);
                int cat = Convert.ToInt32(comboBox3.SelectedValue);
                decimal vente = Convert.ToDecimal(spinEdit2.Value);
                decimal achat = Convert.ToDecimal(spinEdit3.Value);
                int qte = Convert.ToInt32(spinEdit1.Value);
                if(Products.AddProduct(nom,vente,achat,marque,cat,four,qte))
                {
                    XtraMessageBox.Show("Produit ajouté");
                }
                else
                {
                    XtraMessageBox.Show("Erreur lors de l'ajout du produit");
                }
            }
                
        }


    }
}